﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Windstamp.Utility.BookDownload.Common {
    public class UniversalHelper {

        /// <summary>
        /// 当前路径类型
        /// </summary>
        public enum CurrentPathType {
            /// <summary>
            /// 基目录，它由程序集冲突解决程序用来探测程序集
            /// </summary>
            System_AppDomain_CurrentDomain_BaseDirectory,
            /// <summary>
            /// 包含该应用程序的目录的名称
            /// </summary>
            System_AppDomain_CurrentDomain_SetupInformation_ApplicationBase,
            /// <summary>
            /// 模块的完整路径
            /// </summary>
            System_Diagnostics_Process_GetCurrentProcess_MainModule_FileName,
            /// <summary>
            /// 当前工作目录的完全限定路径
            /// </summary>
            System_Environment_CurrentDirectory,
            /// <summary>
            /// 应用程序的当前工作目录
            /// </summary>
            System_IO_Directory_GetCurrentDirectory,
            /// <summary>
            /// 返回调用当前正在执行的方法的方法的程序集的路径或 UNC 位置
            /// </summary>
            System_Reflection_Assembly_GetCallingAssembly_Location,
            /// <summary>
            /// 默认应用程序域中的进程可执行文件的路径或 UNC 位置，Web 应用程序调用时返回值是 null
            /// </summary>
            System_Reflection_Assembly_GetEntryAssembly_Location,
            /// <summary>
            /// 包含当前执行的代码的程序集的路径或 UNC 位置
            /// </summary>
            System_Reflection_Assembly_GetExecutingAssembly_Location
        }
        /// <summary>
        /// 获取当前路径
        /// </summary>
        /// <param name="type">当前路径类型</param>
        /// <returns></returns>
        public static string GetCurrentPaths(CurrentPathType type) {
            string result;
            switch(type) {
                case CurrentPathType.System_AppDomain_CurrentDomain_BaseDirectory:
                    result = System.AppDomain.CurrentDomain.BaseDirectory;
                    break;
                case CurrentPathType.System_AppDomain_CurrentDomain_SetupInformation_ApplicationBase:
                    result = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                    break;
                case CurrentPathType.System_Diagnostics_Process_GetCurrentProcess_MainModule_FileName:
                    result = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                    break;
                case CurrentPathType.System_Environment_CurrentDirectory:
                    result = System.Environment.CurrentDirectory;
                    break;
                case CurrentPathType.System_IO_Directory_GetCurrentDirectory:
                    result = System.IO.Directory.GetCurrentDirectory();
                    break;
                case CurrentPathType.System_Reflection_Assembly_GetCallingAssembly_Location:
                    result = System.Reflection.Assembly.GetCallingAssembly().Location;
                    break;
                case CurrentPathType.System_Reflection_Assembly_GetEntryAssembly_Location:
                    result = System.Reflection.Assembly.GetEntryAssembly().Location;
                    break;
                case CurrentPathType.System_Reflection_Assembly_GetExecutingAssembly_Location:
                    result = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    break;
                default:
                    result = "(null)";
                    break;
            }

            return result;
        }
    }
}
